import { useMutation, useQuery } from "react-query";
import { IPage, IPageParams } from "../types";
import { useRequest } from "../utils/request";




  /**
   * !搜索法律接口
   * @returns
   */
  export const useGetLaws = (queryParams: ILawsSearchParams) => {
    const request = useRequest<IPage<ILaws>>();
    return useQuery(["getLawsBySearch", queryParams], () =>
      request("/laws/getLawsBySearch", { data: queryParams })
    );
  };
  
  /**
   * !添加法律接口
   */
  export const useAddLaws = () => {
    const request = useRequest<string>();
    return useMutation(async (params: IAddLaws) => {
      const result = request("/laws/addLaws", {
        data: params,
        method: "PUT",
      });
      return result;
    });
  };
  
  /**
   * !修改法律接口
   */
  
  export const useUpdateLaws = () => {
    const request = useRequest<string>();
    return useMutation(async (params: UpdateILaws) => {
      const result = request("/laws/updateLawById", {
        data: params,
        method: "POST",
      });
      return result;
    });
  };
  
  /**
   * !删除法律接口
   */
  export const useDeletedlaws = () => {
    const request = useRequest<string>();
    return useMutation(async (params: { lawsId: number }) => {
      const result = request("/laws/deletedLawsById", {
        data: params,
        method: "DELETE",
      });
      return result;
    });
  };

  

export type IAddLaws = {
  /**
   * 法律法规标题
   */
  lawsTitle: string;

  /**
   * 文件名地址
   */
  lawsUrl: string;

  /**
   * 发布单位
   */
  lawsUnitName: string;
};

/**
 * 更新参数
 */
export type UpdateILaws = {
  lawsTypeId: number;
} & Partial<IAddLaws>;

/**
 * 搜索参数类型
 */
export type ILawsSearchParams = {
  lawsTitle: string;
  lawsTypeId?: number;
} & IPageParams;

export type ILaws = {
  /**
   * 法律法规ID
   */
  lawsId: number;

  /**
   * 法律法规标题
   */
  lawsTitle: string;

  /**
   * 文件名地址;pdf
   */
  lawsUrl: string;

  /**
   * 发布单位
   */
  lawsUnitName: string;

  /**
   * 分类ID
   */
  lawsTypeId: number;
};
